package com.aqgj.pubCode.bean;

import com.aqgj.util.BaseEntity;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;
import java.util.Set;

/**
 * Created by zhg on 2017/9/25.
 */
@Entity
@Table(
        name = "PUB_CODE_TABLE"
)
@JsonIgnoreProperties({"codeTableValues"})
public class CodeTable implements BaseEntity{

        private static final long serialVersionUID = 1L;
        private String id;
        private String code;
        private String name;
        private String sort;
        private String remark;
        private String isSystem;
        private String type;
        private Set<CodeTableValue> codeTableValues;

        public CodeTable() {
        }

        @Id
        @GeneratedValue(
                generator = "system-uuid"
        )
        @GenericGenerator(
                name = "system-uuid",
                strategy = "uuid"
        )
        public String getId() {
            return this.id;
        }

        public void setId(String id) {
            this.id = id;
        }

        @Column(
                name = "CODE"
        )
        public String getCode() {
            return this.code;
        }

        public void setCode(String code) {
            this.code = code;
        }

        @Column(
                name = "NAME"
        )
        public String getName() {
            return this.name;
        }

        public void setName(String name) {
            this.name = name;
        }

        @Column(
                name = "SORT"
        )
        public String getSort() {
            return this.sort;
        }

        public void setSort(String sort) {
            this.sort = sort;
        }

        @Column(
                name = "REMARK"
        )
        public String getRemark() {
            return this.remark;
        }

        public void setRemark(String remark) {
            this.remark = remark;
        }

        @Column(
                name = "IS_SYSTEM"
        )
        public String getIsSystem() {
            return this.isSystem;
        }

        public void setIsSystem(String isSystem) {
            this.isSystem = isSystem;
        }

        @Column(
                name = "TYPE"
        )
        public String getType() {
            return this.type;
        }

        public void setType(String type) {
            this.type = type;
        }

        @OneToMany(
                mappedBy = "codeTable",
                cascade = {CascadeType.ALL},
                fetch = FetchType.EAGER
        )
        @OrderBy("sort")
        public Set<CodeTableValue> getCodeTableValues() {
            return this.codeTableValues;
        }

        public void setCodeTableValues(Set<CodeTableValue> codeTableValues) {
            this.codeTableValues = codeTableValues;
        }

        public boolean equals(Object obj) {
            return obj == this?true:(((CodeTable)obj).getId().equals(this.id)?true:obj.hashCode() == this.hashCode());
        }

        public String toString() {
            return "系统码表分类:" + this.name + ",ID:" + this.getId();
        }
    }


